
package com.insigma.business.qrcode.soldier.service.impl;


import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.util.AdminAreaCodeUtils;
import com.insigma.business.qrcode.soldier.dao.CareSoldierEmploymentAssistanceDao;
import com.insigma.business.qrcode.soldier.dto.CareSoldierEmploymentAssistanceBSearcher;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.CareSoldierEmploymentAssistanceDO;
import com.insigma.business.qrcode.soldier.entity.DataStatsCDO;
import com.insigma.business.qrcode.soldier.service.CareSoldierEmploymentAssistanceService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("careSoldierEmploymentAssistanceService")
public class CareSoldierEmploymentAssistanceServiceImpl implements CareSoldierEmploymentAssistanceService {

    @Autowired(required = false)
    private CareSoldierEmploymentAssistanceDao careSoldierEmploymentAssistanceDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<CareSoldierEmploymentAssistanceDO> search(final CareSoldierEmploymentAssistanceBSearcher careSoldierEmploymentAssistanceBSearcher) {
        if (Strings.isNotBlank(careSoldierEmploymentAssistanceBSearcher.getAdminAreaCode())) {
            careSoldierEmploymentAssistanceBSearcher.setAdminAreaCode(AdminAreaCodeUtils.getCutdAreaCode(careSoldierEmploymentAssistanceBSearcher.getAdminAreaCode()));
        }
        return careSoldierEmploymentAssistanceDao.search(careSoldierEmploymentAssistanceBSearcher);
    }

    
    @Override
    public CareSoldierEmploymentAssistanceDO get(final String id) {
        return careSoldierEmploymentAssistanceDao.get(id);
    }

    
    @Override
    public Integer insert(final CareSoldierEmploymentAssistanceDO careSoldierEmploymentAssistanceDO) {
        careSoldierEmploymentAssistanceDO.setId(sequenceGenerator.genKey(SequenceNameConstant.CARE_SOLDIER_EMPLOYMENT_ASSISTANCE_ID));
        return careSoldierEmploymentAssistanceDao.insert(careSoldierEmploymentAssistanceDO);
    }

    
    @Override
    public Integer update(final CareSoldierEmploymentAssistanceDO careSoldierEmploymentAssistanceDO) {
        return careSoldierEmploymentAssistanceDao.update(careSoldierEmploymentAssistanceDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId) {
        return careSoldierEmploymentAssistanceDao.delete(id, modifierType, modifierId);
    }

    @Override
    public CareSoldierEmploymentAssistanceDO getByFormInstId(String formInstId) {
        return careSoldierEmploymentAssistanceDao.getByFormInstId(formInstId);
    }

    @Override
    public List<CareSoldierEmploymentAssistanceDO> listByIdCardNoAndDate(String idCardNo, String today) {
        return careSoldierEmploymentAssistanceDao.listByIdCardNoAndDate(idCardNo, today + "%");
    }

    @Override
    public Integer countByAreaCode(String adminAreaCode) {
        Integer integer = careSoldierEmploymentAssistanceDao.countByAreaCode(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%");
        if (integer == null) {
            integer = 0;
        }
        return integer;
    }

    @Override
    public List<DataStatsCDO> queryAreaMap(String adminAreaCode) {
        int level = AdminAreaCodeUtils.getLevel(adminAreaCode);
        String areaLike = AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%";
        int nextLevel = level + 1;
        int levelLength = AdminAreaCodeUtils.getLevelLength(nextLevel);
        return careSoldierEmploymentAssistanceDao.queryAreaMap(areaLike, nextLevel, levelLength);
    }

    @Override
    public CareSoldierEmploymentAssistanceDO getNewestByIdCardNo(String idCardNo) {
        return careSoldierEmploymentAssistanceDao.getNewestByIdCardNo(idCardNo);
    }

    @Override
    public Integer countByAreaCodeAndTime(String adminAreaCode, String time) {
        return careSoldierEmploymentAssistanceDao.countByAreaCodeAndTime(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode), time);
    }

}
